﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using System.Xml.Serialization;
using System.IO;

namespace GraphicsEngineNamespace
{
    /// <summary>
    /// Klasa zawierająca ustawenia grafiki.
    /// </summary>
    //[Serializable()]
    //[XmlRoot("GraphicsSetting")]
    public class GraphicsSetting// : IXmlSerializable
    {
        /// <summary>
        /// Szerokość ekranu.
        /// </summary>
        private int width = (int)(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width * 0.5f);

        //[XmlElement("Width")]
        public int Width
        {
            get { return width; }
            set { width = value; }
        }    
        /// <summary>
        /// Wysokość ekranu.
        /// </summary>
        private int height = (int)(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height * 0.5f);

        //[XmlElement("Height")]
        public int Height
        {
            get { return height; }
            set { height = value; }
        }  

        /// <summary>
        /// Czy ma być włączona synchronizacja pioniowa.
        /// </summary>
        private bool synchronizeWithVerticalRetrace = false;

        //[XmlElement("SynchronizeWithVerticalRetrace")]
        public bool SynchronizeWithVerticalRetrace
        {
            get { return synchronizeWithVerticalRetrace; }
            set { synchronizeWithVerticalRetrace = value; }
        } 
        /// <summary>
        /// Czy ma być włączony pełny ekran.
        /// </summary>
        private bool isFullScreen = false;

        //[XmlElement("IsFullScreen")]
        public bool IsFullScreen
        {
            get { return isFullScreen; }
            set { isFullScreen = value; }
        }   

        /// <summary>
        /// Czy włączyć antialias.
        /// </summary>
        private bool preferMultiSampling = false;

        //[XmlElement("PreferMultiSampling")]
        public bool PreferMultiSampling
        {
            get { return preferMultiSampling; }
            set { preferMultiSampling = value; }
        } 

        // Opcje antialiasu
        private bool multiSampleAntiAlias = false;  // ??Czy to potrzebne??

        //[XmlElement("MultiSampleAntiAlias")]
        public bool MultiSampleAntiAlias
        {
            get { return multiSampleAntiAlias; }
            set { multiSampleAntiAlias = value; }
        }

        private MultiSampleType multiSampleType = MultiSampleType.None;

        //[XmlElement("MultiSampleType")]
        public MultiSampleType MultiSampleType
        {
            get { return multiSampleType; }
            set { multiSampleType = value; }
        }

        private int multiSampleQuality = 0;   //32

        //[XmlElement("MultiSampleQuality")]
        public int MultiSampleQuality
        {
            get { return multiSampleQuality; }
            set { multiSampleQuality = value; }
        }

        public GraphicsSetting()
        {

        }

        public GraphicsSetting(int width, int height)
        {
            Width = width;
            Height = height;

            Serialization.Serialize(this, this.ToString());
        }

        public GraphicsSetting(int width, int height, bool synchronizeWithVerticalRetrace, bool isFullScreen)
        {
            Width = width;
            Height = height;
            SynchronizeWithVerticalRetrace = synchronizeWithVerticalRetrace;
            IsFullScreen = isFullScreen;

            Serialization.Serialize(this, this.ToString());
        }

        public GraphicsSetting(int width, int height, bool synchronizeWithVerticalRetrace, bool isFullScreen,
            bool multiSampleAntiAlias, MultiSampleType multiSampleType, int multiSampleQuality)
        {
            Width = width;
            Height = height;
            SynchronizeWithVerticalRetrace = synchronizeWithVerticalRetrace;
            IsFullScreen = isFullScreen;
            MultiSampleAntiAlias = multiSampleAntiAlias;
            MultiSampleType = multiSampleType;
            MultiSampleQuality = multiSampleQuality;

            Serialization.Serialize(this, this.ToString());
        }

        /// <summary>
        /// Kopiuje pola z innej klasy to tej klasy.
        /// Jeżeli podany obiekt do kopiowania jest równy null to niekopiuje tylko tworzy nowy zserializowany plik..
        /// </summary>
        /// <param name="gs"></param>
        public void CopyGraphicsSetting(GraphicsSetting toCopyGraphicsSetting)
        {
            if (toCopyGraphicsSetting != null)
            {
                Width = toCopyGraphicsSetting.width;
                Height = toCopyGraphicsSetting.height;
                SynchronizeWithVerticalRetrace = toCopyGraphicsSetting.synchronizeWithVerticalRetrace;
                IsFullScreen = toCopyGraphicsSetting.isFullScreen;
                MultiSampleAntiAlias = toCopyGraphicsSetting.multiSampleAntiAlias;
                MultiSampleType = toCopyGraphicsSetting.multiSampleType;
                MultiSampleQuality = toCopyGraphicsSetting.multiSampleQuality;
            }
            else
            {
                Serialization.Serialize(this, this.ToString());
            }
        }
    }
}
